<% watched_map = current_user.watches.where(:ci_class_name => 'account.Assembly').inject({}) {|m, a| m[a.ci_id] = true; m}
   toolbar = {:list_name => 'assemblies',
              :sort_by   => [%w(Name ciName), %w(Created created), %w(Favorite favorite:ciName), %w(Watching watching:ciName)],
              :filter_by => %w(ciName favorite watching)}
   menu = [{:id => 'watch',   :label => icon('eye', 'Watch',  'fa-fw'),  :url => watch_path, :method => :post,   :param_name => 'ciIds'},
           {:id => 'unwatch', :label => icon('eye-slash','Ignore', 'fa-fw'), :url => watch_path, :method => :delete, :param_name => 'ciIds'}] %>
<%= ci_list(@assemblies,
            :toolbar => toolbar,
            :menu => menu,
            :new_link => (creates_assemblies? ? link_to(icon('plus', 'New Assembly...'), new_assembly_path) : nil)) do |builder, target| %>
  <% favorite = current_user.favorite(target.ciId)
     watching = watched_map[target.ciId] %>
  <% builder.attributes raw(%(ciName="#{target.ciName}" created="#{target.created}" favorite="#{favorite ? 'favorite' : '~!'}" watching="#{watching ? 'watching' : '~!'}")) %>
  <% builder.target link_to('', assembly_path(target), :remote => false) %>
  <% builder.status do %>
    <%= marker(icon('eye', 'watching', 'fa-lg'), 'label-inverse') if watching %>
  	<%= status_marker('design', 'open', 'label-info') if target.release && target.release.releaseState == 'open' %>
  <% end %>
  <% builder.menu do |ci| %>
    <%= link_to(icon('edit', ' Edit'),   assembly_path(ci, :anchor => 'profile')) %>
    <% if creates_assemblies? %>
      <%= link_to(icon('files-o',  ' Copy'),  new_clone_assembly_path(ci), :remote => true) %>
      <%= link_to(icon('floppy-o', ' Save to Catalog'), new_clone_assembly_path(ci, :export => 'catalog'), :remote => true) %>
    <% end %>
  <% end %>
  <% builder.icon :none %>
  <% builder.top do %>
    <span class="topname"><%= target.ciName %></span>
    <% if favorite %>
      <span class="favorite"><%= icon('bookmark') %></span>
    <% end %>
  <% end %>
  <% builder.middle do %>
    <%= link_to(icon(site_icon(:design),     'design'),     assembly_design_path(target)) %> <%= highlight(target.platforms.count) %> <%= 'platform'.pluralize(target.platforms.count) %> |
    <%= link_to(icon(site_icon(:transition), 'transition'), assembly_transition_path(target)) %> <%= highlight(target.environments.count) %> <%= 'environment'.pluralize(target.environments.count) %> |
    <%= link_to(icon(site_icon(:operations), 'operations'), assembly_operations_path(target)) %>
  <% end %>
  <% builder.bottom do %>
    created by <%= target.createdBy %>
    <%= time_ago_in_words(target.created_timestamp) %>
    &mdash;
    <% if target.release %>
      last design release <%= target.release.releaseState %>
      by <%= target.release.releaseState == 'open' ? target.release.createdBy : target.release.commitedBy %>
      <%= time_ago_in_words(target.release.updated_timestamp) %>
    <% else %>
      no design release
    <% end %>
  <% end %>
<% end %>
